package com.nuaa.dao.change.impl;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.stereotype.Repository;

import com.nuaa.dao.base.impl.BaseDaoImpl;
import com.nuaa.dao.change.inter.ProductDaoInter;
import com.nuaa.domain.change.ProductEntity;
import com.nuaa.utils.AjaxMsg;
/**
 * 产品信息Dao
 * @author heaven
 *
 */
@Repository("proDao")
public class ProductDaoImpl extends BaseDaoImpl<ProductEntity, Integer> implements ProductDaoInter{
	/**保存所有产品信息*/
	@Override
	@Transactional
	public AjaxMsg saveProducts(List<ProductEntity> entityList){
		AjaxMsg msg = new AjaxMsg();
		msg.setSuccess(true);
		msg.setMsg("提交产品信息成功！");
		if(entityList.size()==0){
			return msg;
		}
		try{
			for(ProductEntity entity : entityList){
				this.save(entity);
			}
		}catch(Exception e){
			msg.setSuccess(false);
			msg.setMsg("提交产品信息失败！");
		}
		return msg;
	}

	@Override
	public List<ProductEntity> selectByOrderNo(String orderNo, int start, int last) {
		String sql = String.format("select * from pro_info where order_no = '%s'", orderNo);
		return search(ProductEntity.class, sql, start, last);
	}
	@Override
	public long countbyOrderNo(String orderNo){
		String sql = String.format("select * from pro_info where order_no = '%s'", orderNo);
		return super.count(sql);
		
	}
}
